<?php
namespace Home\Controller;
use Think\Controller;

class ActivateController extends CommonController
{
    public function activate()
    {
        $failure = time()-86400;//有效期24小时(86400秒)
        $condition = ['useful'=>'1',
                      'token'=>I('get.token'),
                      '_logic'=>'and'];
        // $data = D('token')->where($condition)->relation(true)->find();
        $data = D('UserToken')->where($condition)->relation(true)->find();
        // var_dump($data);exit;
        if ($data['create_time'] >= $failure) {
            $condition = 'uid='.$data['uid'];
            M('user_token')->where($condition)->save(['useful'=>'0']);
            M('users')->where($condition)->save(['act_email'=>'1']);
            $this->success('激活成功',U('home/index/index'),3);
        }else{
            $this->error('激活码已失效',U('home/index/index'),3);
        }
    }
}
